// 导入requestUtil
import {requestUtil, getBaseUrl} from '../../util/resultUtil'
Page({
  data:{
    swiperList:[],
    baseurl: '',
    bigTypeList: [],
    bigTypeList_row1: [],
    bigTypeList_row2: [],
    HotProductList: [],
  },
  onLoad(){
    // 原始使用方法
    
    this.setData({
      baseurl: getBaseUrl()
    });
    this.getSwiperList();
    this.getBigTyleList();
    this.getHotProductList();
  },

  async getSwiperList(){
    const resp = await requestUtil({url: "/product/findSwiper/", method: 'get'});
    this.setData({
      swiperList: resp.data,
    });
  },
  // 商品大类
  async getBigTyleList(){
    const resp = await requestUtil({url: "/bigType/findAll/", method: "get"});
    let bigTypeList = resp.data;
    let bigTypeList_row1 = bigTypeList.filter((item, index) =>{
      return index < 5;
    });
    let bigTypeList_row2 = bigTypeList.filter((item, index) =>{
      return index >= 5 && index < 10;
    })
    this.setData({
      bigTypeList,
      bigTypeList_row1,
      bigTypeList_row2
    })
  },
   // 热卖商品
  async getHotProductList(){
    const resp =await requestUtil({url: '/product/findHot/', method: 'get'});
    this.setData({
      HotProductList: resp.data.hotProducts,
    })
  },
  handleJumpPage(e){
    const data = e.currentTarget.dataset;

    const app = getApp();
    app.globalDate.index = data.index;
    wx.switchTab({
      url: '/pages/category/index',
      success: resp=>{
        console.log(resp);
      },
      fail: resp=>{
        console.log(resp);
      }
    })
  }
})
